using UnityEngine;
using System.Collections.Generic;

public class SlowZone : MonoBehaviour {

	List<MonsterBehaviour> mbs;



	void OnTriggerEnter2D(Collider2D col) {
		if(mbs == null)
			mbs = new List<MonsterBehaviour>();

		MonsterBehaviour mb = col.GetComponent<MonsterBehaviour>();
		if(mb != null) {
			mb.inSlowZone++;
			mbs.Add(mb);
		}
	}

	void OnTriggerExit2D(Collider2D col) {
		if(mbs == null)
			mbs = new List<MonsterBehaviour>();

		MonsterBehaviour mb = col.GetComponent<MonsterBehaviour>();
		if(mb != null) {
			mb.inSlowZone--;
			mbs.Remove(mb);
		}
	}

	void OnDestroy() {
		if(mbs != null) {
			foreach(MonsterBehaviour mb in mbs) {
				mb.inSlowZone--;
			}
		}
	}

}
